home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / util / pack / xpk_Source.lha / xpk_Source / test / FindFileType.c < prev    next >
C/C++ Source or Header  |  1998-11-09  |  3KB  |  113 lines

  1. #define NAME        "FindFileType"
  2. #define DISTRIBUTION    "(Freeware) "
  3. #define REVISION    "1"
  4.  
  5. /* NOTE: This program depends on certain things, which may change. It is
  6. only valid as long as the XpkMasterPrefs internal structures do not change.
  7. It is only for tests and no standard use tool!!! Never distribute a binary
  8. version of it or use it's routines in other programs! */
  9.  
  10. /* Programmheader
  11.  
  12.     Name:        FindFileType
  13.     Author:        SDI
  14.     Distribution:    Freeware
  15.     Description:    shows filetype scanned with XpkMasterPrefs
  16.     Compileropts:    -
  17.     Linkeropts:    -l amiga
  18.  
  19.  1.0   05.04.97 : first Version
  20.  1.1   18.06.97 : now passes file size
  21. */
  22.  
  23. #include <proto/dos.h>
  24. #include <proto/exec.h>
  25. #include <exec/memory.h>
  26. #include <xpk/xpkprefs.h>
  27. #include "SDI_defines.h"
  28.  
  29. struct XpkTypeNode {
  30.   struct Node        xtn_Node;    /* standard node structure */
  31.   ULONG            xtn_Size;    /* hold complete size to free */
  32.   struct XpkTypePrefs    xtn_TypePrefs;  /* real data */
  33. };
  34.  
  35. #define PARAM "FILE/M/A"
  36.  
  37. #ifdef __MAXON__
  38.   #define __asm
  39. #endif
  40.  
  41. typedef struct XpkTypeData * __asm (*RecogFunc) (register __a0 STRPTR,
  42.   register __a1 STRPTR, register __a2 STRPTR, register __d0 ULONG,
  43.   register __d1 ULONG);
  44.  
  45. void main()
  46. {
  47.   STRPTR *files;
  48.   struct XpkPrefsSemaphore *semaphore;
  49.   ULONG fh, bufsize;
  50.   LONG size;
  51.   STRPTR buf;
  52.   struct XpkTypeData *td;
  53.  
  54.   struct RDArgs *rda;
  55.  
  56.   if((rda = ReadArgs(PARAM, (LONG *) &files, 0)))
  57.   {
  58.     Forbid();
  59.     if((semaphore = (struct XpkPrefsSemaphore *) FindSemaphore(XPKPREFSSEMNAME)))
  60.       ObtainSemaphoreShared((struct SignalSemaphore *) semaphore);
  61.     Permit();
  62.     if(semaphore)
  63.     {
  64.       if(semaphore->xps_PrefsType == XPREFSTYPE_STANDARD)
  65.       {
  66.     if((buf = (STRPTR) AllocMem((bufsize = semaphore->xps_RecogSize), MEMF_ANY)))
  67.     {
  68.           while(*files)
  69.           {
  70.         if((fh = Open(*files, MODE_OLDFILE)))
  71.         {
  72.           size = Read(fh, buf, bufsize);
  73.           if(size != -1)
  74.           {
  75.               Seek(fh, 0, OFFSET_END);
  76.                 td = ((RecogFunc)semaphore->xps_RecogFunc)
  77.         (buf, *files, *files, size, Seek(fh, 0, OFFSET_END));
  78.         if(semaphore->xps_PrefsData)
  79.         {
  80.           struct Node *n;
  81.           for(n = ((struct List *)semaphore->xps_PrefsData)->lh_Head;
  82.           n->ln_Succ; n = n->ln_Succ)
  83.           {
  84.             if(((struct XpkTypeNode *) n)->xtn_TypePrefs.
  85.             xtp_PackerData == td)
  86.             {
  87.               Printf("%s is '%s'\n", *files, ((struct XpkTypeNode *)
  88.               n)->xtn_TypePrefs.xtp_TypeName);
  89.               break;
  90.             }
  91.           }
  92.           if(!n->ln_Succ)
  93.             Printf("%s is default type\n", *files);
  94.         }
  95.           }
  96.           else
  97.             Printf("%s cannot be read\n", *files);
  98.           Close(fh);
  99.         }
  100.         else
  101.           Printf("%s does not exist\n", *files);
  102.           ++files;
  103.           }
  104.     }
  105.     FreeMem(buf, bufsize);
  106.       }
  107.       ReleaseSemaphore((struct SignalSemaphore *) semaphore);
  108.     }
  109.     FreeArgs(rda);
  110.   }
  111. }
  112.  
  113.